/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mvc;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import mvc.Users;

/**
 *
 * @author tadiwa
 */
@Stateless
public class UsersFacade extends AbstractFacade<Users> {

    @PersistenceContext(unitName = "yappPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public UsersFacade() {
        super(Users.class);
    }

    public Users getUserByUsername(String username) {
        try {
            Query query = em.createNamedQuery("Users.findByUsername");
            query.setParameter("username", username);
            Users u = (Users) query.getSingleResult();
            return u;
        } catch (Exception e) {
            //e.printStackTrace(System.out);
            return null;
        }
    }
}
